<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作业管理 - 析码无界</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background-color: #f5f5f5;
            padding-top: 20px;
        }
        .navbar {
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            border: none;
        }
        .navbar-brand, .navbar-nav > li > a {
            color: white !important;
        }
        .panel {
            border: none;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            border-radius: 8px;
        }
        .panel-heading {
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 8px 8px 0 0;
        }
        .badge-published { background-color: #5cb85c; }
        .badge-grading { background-color: #f0ad4e; }
        .badge-finished { background-color: #5bc0de; }
    </style>
</head>
<body>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" th:href="@{/teacher}">
                    <i class="fa fa-arrow-left"></i> 返回主页
                </a>
            </div>
            <ul class="nav navbar-nav">
                <li><a th:href="@{/assignment/publish}">发布作业</a></li>
                <li><a th:href="@{/assignment/grading}">批改作业</a></li>
                <li><a th:href="@{/assignment/finished}">已结束作业</a></li>
            </ul>
        </div>
    </nav>
    
    <div class="container">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-book"></i> 作业列表</h3>
            </div>
            <div class="panel-body">
                <div th:if="${error}" class="alert alert-danger" th:text="${error}"></div>
                <div th:if="${message}" class="alert alert-success" th:text="${message}"></div>
                
                <div class="alert alert-info">
                    <a th:href="@{/assignment/publish}" class="btn btn-primary">
                        <i class="fa fa-plus"></i> 发布新作业
                    </a>
                    <a th:href="@{/assignment/list}" class="btn btn-default">全部</a>
                    <a th:href="@{/assignment/list(status='published')}" class="btn btn-default">已发布</a>
                    <a th:href="@{/assignment/list(status='grading')}" class="btn btn-default">批改中</a>
                    <a th:href="@{/assignment/list(status='finished')}" class="btn btn-default">已结束</a>
                </div>
                
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>标题</th>
                            <th>班级</th>
                            <th>发布时间</th>
                            <th>截止时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr th:if="${#lists.isEmpty(assignments)}">
                            <td colspan="6" class="text-center">暂无作业</td>
                        </tr>
                        <tr th:each="assignment : ${assignments}">
                            <td>
                                <a th:href="@{/assignment/viewStudents(assignmentId=${assignment.id})}" 
                                   style="color: #667eea; text-decoration: none; font-weight: bold;"
                                   th:text="${assignment?.title} ?: '无标题'"></a>
                            </td>
                            <td>
                                <span th:each="clazz : ${allClasses}" 
                                      th:if="${clazz.id == assignment.classId}"
                                      th:text="${clazz.className}"></span>
                                <span th:if="${assignment?.classId == null}">-</span>
                            </td>
                            <td th:text="${assignment?.publishTime != null ? #dates.format(assignment.publishTime, 'yyyy-MM-dd HH:mm') : '-'}"></td>
                            <td th:text="${assignment?.deadline != null ? #dates.format(assignment.deadline, 'yyyy-MM-dd HH:mm') : '-'}"></td>
                            <td>
                                <span class="badge badge-published" th:if="${assignment?.status == 'published'}">已发布</span>
                                <span class="badge badge-grading" th:if="${assignment?.status == 'grading'}">批改中</span>
                                <span class="badge badge-finished" th:if="${assignment?.status == 'finished'}">已结束</span>
                                <span th:if="${assignment?.status == null or (assignment?.status != 'published' and assignment?.status != 'grading' and assignment?.status != 'finished')}">-</span>
                            </td>
                            <td>
                                <a th:href="@{/assignment/viewStudents(assignmentId=${assignment.id})}" 
                                   class="btn btn-sm btn-info" style="margin-right: 5px;">
                                    <i class="fa fa-users"></i> 查看学生完成情况
                                </a>
                                <form th:action="@{/assignment/finish}" method="post" style="display: inline;" th:if="${assignment?.status != null and assignment?.status != 'finished'}">
                                    <input type="hidden" name="id" th:value="${assignment?.id}"/>
                                    <button type="submit" class="btn btn-sm btn-success" 
                                            onclick="return confirm('确定要结束该作业吗？')">
                                        <i class="fa fa-check"></i> 结束
                                    </button>
                                </form>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>
</html>

